package com.byzk.p2p.admin.group.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.group.dao.GroupDao;
import com.byzk.p2p.admin.group.dto.Group;

@Service
public class GroupService {

	@Autowired
	private GroupDao groupDao;
	
	public PageInfo<Group> groupList(Map<String, Object> queryMap,Integer index,Integer limit){
		if (index != null && limit != null) {
			if (queryMap == null) {
				queryMap = new HashMap<String, Object>();
			}
			queryMap.put("start", (index-1)*limit);
			queryMap.put("limit", limit);
		}
		Integer total = groupDao.count(queryMap);
		List<Group> list = groupDao.groupList(queryMap);
		PageInfo<Group> pageInfo = new PageInfo<Group>(total, index, limit);
		pageInfo.setPageList(list);
		return pageInfo;
	}
	
	public int saveOrUpdateGroup(Group group){
		if(group.getId()==null){
			return groupDao.insert(group);
		}else{
			return groupDao.update(group);
		}
	}
	
	public Group getGroupById(Integer id){
		return groupDao.getGroupById(id);
	}
	
	public Integer deleteGroup(Integer id){
		return groupDao.delete(id);
	}
	
	public List<Group> getAllGroup(){
		return groupDao.getAllGroup();
	}
}
